import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/page/rong_im/util/rong_widget.dart';
import 'package:flutter_ncsjqz_getx/util/get_user_util.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/input_widget.dart';
import 'package:get/get.dart';

import 'search_add_friend_logic.dart';

/// <summary>
/// author：zwb
/// dateTime： 2022/1/17 15:14
/// filePath： lib/page/rong_im/commom/add_friend/search_add_friend_view.dart
/// desc: 搜索添加好友
/// <summary>
///
class SearchAddFriendPage extends StatefulWidget {
  @override
  _SearchAddFriendPageState createState() => _SearchAddFriendPageState();
}

class _SearchAddFriendPageState extends State<SearchAddFriendPage> {
  final logic = Get.put(SearchAddFriendLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: appBarWidget(title: "添加好友"),
      body: GetBuilder<SearchAddFriendLogic>(
        builder: (controller) {
          return Container(
            padding: EdgeInsets.all(15),
            child: Column(
              children: [
                _searchBar(),

                logic.getFriendData.id == null ? SizedBox():ListTile(
                  leading: InkWidget.imgNet("${logic.getFriendData.userPic}",width: 50,height: 50,borderRadius: BorderRadius.circular(5)),
                  title: InkWidget.title("${logic.getFriendData.nickName}",fonSize: 16),
                  subtitle: InkWidget.text("${logic.getFriendData.selfIntroduction }",fonSize: 13),
                  trailing: logic.getFriendData.id == getUserUtil().userId ? SizedBox() : SizedBox(
                    width: 90,
                    height: 35,
                    child:  RongWidget.gradientButton(logic.getFriendData.isFriend!?"已是好友":"添加好友",onTap: logic.getFriendData.isFriend! ? null : (){
                      logic.friendApply(logic.getFriendData.id);
                    },color: logic.getFriendData.isFriend! ? Colors.grey:null,),
                  ),
                ),
              ],
            ),

          );
        },
      ),
    );
  }

  /// todo：搜索栏
  _searchBar() {
    return SafeArea(
      child: Container(
        width: Get.width,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(
              child: textFieldWidget(
                controller: logic.textEditingController,
                circular: 5,
                height: 40,
                bgColor: Colors.grey.shade100,
                hintText: "搜索对方手机号",
                prefixIcon: Icon(Icons.search,color: Colors.grey,size: 30,),
                onSubmitted: (v){
                }
              ),
            ),
            SizedBox(
              width: 10,
            ),
            MaterialButton(onPressed: (){
              logic.search(logic.textEditingController.text);
            },child: InkWidget.text("搜 索",color: Colors.white),color: Colors.green,),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<SearchAddFriendLogic>();
    super.dispose();
  }
}